﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.ServiceModel.Security;
	using System.Text;

	/// <summary>
	/// Manages twitter help utilities like testing for the service and 
	/// finding the scheduled downtime. 
	/// </summary>
	public class HelpClient : TwitterClient<IHelpClient>, IHelpClient 
	{

		/// <summary>
		/// Initializes a new instance of the <see cref="HelpClient"/> class.
		/// </summary>
		/// <param name="username">The username.</param>
		/// <param name="password">The password.</param>
		public HelpClient(string username, string password)
			: base(username, password)
		{

		}

		#region IHelpClient Members

		/// <summary>
		///		Tests the twitter Client and returns true if the Client is running fine.
		/// </summary>
		/// <returns>returns a string message &quot;ok&quot;.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public string Test()
		{
			try
			{
				return this.Proxy.Test();
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		///		Gets the downtime schedule, its comes as an error,
		///		the string &quot;Error&quot; property.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The schedule infor comes back in the error property of the object and 
		///			it includes css information inside of that string fo whatever reason.
		///			otherwise the error property comes back null.
		///		</para>
		/// </remarks>
		/// <example>
		///		<code class="code csharp">
		///			HelpClient client = new HelpClient("username", "password");
		///			TwitterError obj = client.GetScheduledDowntime();
		///			if(obj.HasError)
		///			    MessageBox.Show("no downtime");
		///			else
		///				MessageBox.Show(obj.Error);
		///		</code>
		/// </example>
		/// <returns>returns a <see cref="Amplify.Twitter.TwitterError"/>. </returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public TwitterError GetScheduledDowntime()
		{
			try 
			{
				return this.Proxy.GetScheduledDowntime();
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		#endregion
	}
}
